/*******************************************************************************
* 
* Utility for running process
* 
* 
******************************************************************************/
#include "process.h"

#include <windows.h>
#include <psapi.h>
#include <process.h>

#pragma comment (lib, "psapi.lib")

namespace noria{ namespace diagnostic
{
    wstring Process::getBaseName()
    {
        wchar_t name[MAX_PATH] = {0};
        GetModuleBaseName(GetCurrentProcess(), NULL, name, MAX_PATH);
        return wstring(name);
    }

    wstring Process::getFileName()
    {
        wchar_t name[MAX_PATH] = {0};
        GetModuleFileName(NULL, name, MAX_PATH);
        return wstring(name);
    }

    int Process::getpid()
    {
        return _getpid();
    }

    wstring Process::getModulePath(const wstring& module)
    {
        wchar_t szPath[MAX_PATH];

        if(GetModuleFileNameW(GetModuleHandleW(module.c_str()), szPath, MAX_PATH) == 0)
        {
            return wstring();
        }

        wstring path = szPath;
        auto lastBackSlash = path.find_last_of(L'\\');

        return path.substr(0, lastBackSlash);

    }
}}